import path from "path"
import IconsResolver from "unplugin-icons/resolver"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"

/**
 * 组件自动按需引入插件
 *
 * @param rootPath 根路径
 * @returns 组件插件
 */
export function configComponentsPlugin(rootPath: string) {
    return Components({
        extensions: ['vue', 'md'],
        include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
        resolvers: [
            ElementPlusResolver({
                importStyle: 'sass'
            }),
            IconsResolver()
        ],
        dts: path.resolve(rootPath, './components.d.ts')
    })
}